<template>
  <div class="edu-page-warp" id="schoolMajorDiv">
    <inner-breadcrumb v-model="pathKey" :path="path" v-show="pathKey!='main'"></inner-breadcrumb>
    <template v-if="pathKey=='main'">
      <condition-card @reset="reset" @search="getCampusProfessions">
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('label.grade')" prop="grade">
              <el-date-picker
                v-model="queryForm.grade"
                value-format="yyyy"
                type="year"
                :placeholder="$t('message.plsSelect')"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingLevel')" prop="trainingLevel">
              <DictSelect v-model="queryForm.trainingLevel" :data="options.trainingLevel"></DictSelect>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              :label="$t('label.college')"
              :placeholder="$t('message.all')"
              prop="faculty"
            >
              <DictSelect v-model="queryForm.faculty" :data="options.faculty" :filterable="true"></DictSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item :label="$t('professions.category')" prop="professionCateGory">
              <DictSelect v-model="queryForm.category" :data="options.category"></DictSelect>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('professions.isArts')">
              <DictSelect v-model="queryForm.isArts" :data="options.isArts"></DictSelect>
            </el-form-item>
          </el-col>
        </el-row>
      </condition-card>
      <el-card shadow="never" body-style="padding: 24px;">
        <div class="edu-page-title" style="margin-bottom: 16px;">{{$t('label.major')}}</div>
        <div class="edu-opertion-bar" style="margin-bottom: 16px;">
          <div class="float-left">
            <el-input
              v-model="queryForm.keyWord"
              :placeholder="$t('culture.profession.searchForProCodeOrname')"
              style="width:250px"
              @keyup.enter.native="getCampusProfessions"
            >
              <i
                class="el-icon-search"
                slot="suffix"
                style="margin-top:10px;cursor:pointer"
                @click="getCampusProfessions()"
              ></i>
            </el-input>
          </div>         
        </div>
        <el-table
          :data="tableData"
          size="mini"
          stripe
          tooltip-effect="light"
        >
          <edu-table-column type="index" width="60" :label="$t('message.order')" align="center"></edu-table-column>
          <edu-table-column width="60" :label="$t('label.grade')">
            <template slot-scope="scope">{{scope.row.grade}}</template>
          </edu-table-column>
          <edu-table-column width="80" :label="$t('culture.profession.proCode')">
            <template slot-scope="scope">{{scope.row.professionCode}}</template>
          </edu-table-column>
          <edu-table-column  :label="$t('culture.profession.proCodeName')">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="viewProfession(scope.row)"
                size="mini"
              >{{$t(scope.row.professionName)}}</el-button>
            </template>
          </edu-table-column>
          <edu-table-column
            :label="$t('culture.profession.proCodeNameEn')"
            prop="professionNameEn"
          />
          <edu-table-column :label="$t(' professions.isArts')" min-width="60">
            <template slot-scope="scope">
              <label v-if="scope.row.isArts || scope.row.isArts === 1">{{$t('message.yes')}}</label>
              <label v-else>{{$t('message.no')}}</label>
            </template>
          </edu-table-column>

          <edu-table-column
            width="80"
            :label="$t('label.trainingLevel')"
            prop="trainingLevelI18n"
          />
          <edu-table-column width="50" :label="$t('label.lengthSchooling')">
            <template slot-scope="scope">{{scope.row.lengthSchooling}}</template>
          </edu-table-column>
          <edu-table-column width="120" :label="$t('label.college')" prop="facultyI18n" />
          <edu-table-column
            width="80"
            :label="$t('culture.profession.categoryCode')"
            prop="subjectCategory"
          />
          <edu-table-column :label="$t('message.operating')" width="80">
            <template slot-scope="scope">
              <el-button
                type="text"                
                @click="directionDetail(scope.row)"
                size="mini"
              >{{$t('professions.administrativeClass')}}</el-button>                          
            </template>
          </edu-table-column>
        </el-table>
        <div class="edu-pagination">
          <div class="float-right">
            <el-pagination
              @size-change="onPageSizeChange"
              @current-change="onCurrentPageChange"
              :current-page="queryForm.pageNum_"
              :page-sizes="[20, 50, 100,500,1000]"
              :page-size="queryForm.pageSize_"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryForm.total_"
              style="float: right;margin:10px 60px 0 0;"
            ></el-pagination>
          </div>
        </div>
      </el-card>
      <el-dialog
        :title="$t('message.Look')"
        width="1000px"
        class="gCourseAddDialog"
        :visible.sync="showDialog"
        @close="resetFormValidate()"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-drag-dialog
      >
        <el-form
          :model="model"
          ref="model"
          :rules="rules"
          label-direction="right"
          label-width="140px"
          label-suffix=":"
        >
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('dic.grade')" prop="grade">
                <el-date-picker
                  :disabled="true"
                  v-model="model.grade"
                  :placeholder="$t('message.plsSelect')"
                  type="year"
                  value-format="yyyy"
                  style="width: 100%;"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('dic.faculty')" prop="faculty">
                <DictSelect
                  :disabled="true"
                  v-model="model.faculty"
                  filterable
                  :plzSelect="true"
                  :data="options.faculty"
                ></DictSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('dic.trainingLevel')" prop="trainingLevel">
                <DictSelect
                  :disabled="true"
                  v-model="model.trainingLevel"
                  filterable
                  :plzSelect="true"
                  :data="options.trainingLevel"
                  @change="findToDegreeListByTrainingLevelId"
                ></DictSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('culture.profession.proCode')" prop="professionCode">
                <el-input
                  :disabled="true"
                  v-model="model.professionCode"
                  :placeholder="$t('culture.rules.plsInputProCode')"
                  style="width: 100%"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('culture.profession.proCodeName')" prop="professionName">
                <el-input
                  v-model="model.professionName"
                  :disabled="true"
                  :placeholder="$t('culture.rules.plsInputProName')"
                  style="width: 100%;"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('culture.profession.proCodeNameEn')" prop="professionNameEn">              
                <el-input
                  v-model="model.professionNameEn"
                  :disabled="true"
                  :placeholder="$t('culture.rules.plsInputProNameEN')"
                  style="width: 100%;"
                  maxlength="128"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('culture.profession.category')" prop="category">
                <DictSelect
                  v-model="model.category"
                  :disabled="true"
                  filterable
                  :plzSelect="true"
                  :data="options.category"
                ></DictSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                :label="$t('culture.profession.categoryCode')"
                ref="categoryCode"
              >
                <DictSelect
                  :disabled="true"
                  v-model="model.categoryCode"                 
                  :plzSelect="true"
                  :data="options.categoryCode"
                ></DictSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                :label="$t('culture.profession.professionClassCode')"
                ref="professionClassCodeModel"
              >
                <DictSelect
                  :disabled="true"
                  v-model="model.professionClassCode"                 
                  :plzSelect="true"
                  :data="options.professionClass"
                ></DictSelect>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item
                :label="$t('culture.profession.ministryEduCode')"
                ref="ministryEduCodeModel"
              >
                <DictSelect
                  :disabled="true"
                  v-model="model.ministryEduCode"
                  :plzSelect="true"
                  :data="options.ministryEduCode"
                ></DictSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('label.lengthSchooling')" prop="lengthSchooling">
                <DictSelect
                :disabled="true"
                  v-model="model.lengthSchooling"
                  :data="options.lengthSchooling"
                  :plzSelect="true"
                ></DictSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('label.toDegree')">
                <DictSelect
                 :disabled="true"
                  v-model="model.toDegree"
                  :data="options.toDegree"
                  multiple
                  :collapseTags="true"
                  :plzSelect="true"
                ></DictSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                :label="$t('culture.profession.belongBigProfession')"
                ref="belongBigProfessionModel"
              >
                <DictSelect
                 :disabled="true"
                  v-model="model.belongBigProfession"
                  :plzSelect="true"
                  :data="options.belongBigProfession"
                ></DictSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('professions.isArts')" prop="isArts">
                <el-select style="width:100%;" v-model="model.isArts"  :disabled="true">
                  <el-option v-for="item in options.isArts" :key="item.value" :label="item.label" :value="item.value"/>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('professions.beginTerm')" prop="startTime">
                <DictSelect
                 :disabled="true"
                  v-model="model.startTime"
                  :data="options.beginSemester"
                  :plzSelect="true"
                  @change="handleSemesterChange1(1)"
                ></DictSelect>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item :label="$t('professions.endTerm')" prop="endTime">
                <DictSelect
                  :disabled="true"
                  v-model="model.endTime"
                  :plzSelect="true"
                  :data="options.endSemester"
                  @change="handleSemesterChange1(2)"
                ></DictSelect>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item
                :label="$t('culture.profession.proDirection')"
                v-if="this.model.category=='2'"
              >
                <el-input v-model="direcModel.direction" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item :label="$t('culture.profession.enrollTwice')">
                <el-switch
                  :disabled="true"
                  v-model="model.enrollTwice"
                  :active-text="$t('common.text.no')"
                  :inactive-text="$t('common.text.yes')"
                  active-value="2"
                  inactive-value="1"
                  active-color="#B8BFC5"
                  inactive-color="#3A7FE8"
                ></el-switch>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('message.remark')">
                <el-input
                  :disabled="true"
                  v-model="model.remark"
                  type="textarea"
                  :rows="3"
                  style="width:100%"
                  maxlength="255"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer">
          <el-button
            @click="showDialog = false"
          >{{$t('message.close')}}</el-button>
        </span>
      </el-dialog>      
    </template>

   <AdministrativeClassComponent v-show="pathKey=='dirName'" @back="pathKey='main'" ref="administrativeClassBread"></AdministrativeClassComponent>
  </div>
</template>
<script>
import bus from "common/src/utils/bus";
import UTILS from "common/src/utils/utils";
import { queryDic, findTrainingLevelByProjId } from "common/src/api/dictionary";
import {
  findCategoryList,
  findProfessionClassList,
  findProfessionList,
  findDegreeTypeByTrainingLevel
} from "common/src/api/culture/eduProfession";
import {
  findCampusProfessionList,
  findCampusProById,
  findProByParam,
  findBigProByParam,
  findDirMaintenByPro
} from "common/src/api/culture/campusProfession";
import AdministrativeClassComponent from "./component/AdministrativeClassComponent";
import { getFacultys } from "common/src/api/resource/course";

export default {
  name: "administrativeClass",
  components: {
    AdministrativeClassComponent
  },
  data() {
    return {
      path: {
        label: this.$t("professions.proManagne"),
        key: "belong",
        disable: true,
        children: [
          {
            label: this.$t("professions.campusProManage"),
            key: "main",
            children: [
              {
                label: this.$t("professions.professionDirection"),
                key: "direction",
                disable: true,
                children: [
                  {
                    label: "",
                    key: "dirName"
                  }
                ]
              }
            ]
          }
        ]
      },
      pathKey: "main",
      // isRequired: true,
      isClearCateCode: true,
      isClearProCode: true,
      isClearBelong:true,
      isClearCate:true,
      isYuKe: false,
      tableData: [],
      table: [],
      showDialog: false,
      queryForm: {
        pageNum_: 1,
        pageSize_: 20,
        total_: 0,
        copyGrade: "",
        grade: "",
        trainingLevel: "",
        faculty: "",
        keyWord: "",
        category: "",
        inUsed: "0",
        isArts: null
      },
      model: {
        grade: "",
        faculty: "",
        trainingLevel: "",
        professionCode: "",
        professionName: "",
        professionNameEn: "",
        category: "",
        categoryCode: null,
        professionClassCode: null,
        ministryEduCode: null,
        campusEduProRelations: [],
        lengthSchooling: "",
        toDegree: [],
        belongBigProfession: "",
        isArts:false,
        startTime: "",
        endTime: "",
        remark: "",
        enrollTwice: "2"
      },
      direcModel: {
        direction: ""
      },
      options: {
        grade: [],
        trainingLevel: [],
        faculty: [],
        category: [],
        categoryCode: [],
        professionClass: [],
        ministryEduCode: [],
        lengthSchooling: [],
        toDegree: [],
        allToDegree: [],
        belongBigProfession: [],
        beginSemester: [],
        endSemester: [],
        category: [],
        isArts: []
      },
      rules: {
        grade: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseGrade"),
            trigger: "blur"
          }
        ],
        copyGrade: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseGrade"),
            trigger: "blur"
          }
        ],
        copyOrigin: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseGrade"),
            trigger: "blur"
          }
        ],
        faculty: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseFaculy"),
            trigger: "change"
          }
        ],
        trainingLevel: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseTrainingLevel"),
            trigger: "change"
          }
        ],
        professionCode: [
          {
            required: true,
            message: this.$t("culture.rules.proCodeReq"),
            trigger: "blur"
          }
        ],
        professionName: [
          {
            required: true,
            message: this.$t("culture.rules.proNameReq"),
            trigger: "blur"
          }
        ],
        professionNameEn: [
          {
            // validator: validateNameEn,
            trigger: "blur"
          },
          {
            required: true,
            message: this.$t("culture.rules.proNameEnReq"),
            trigger: "blur"
          }
        ],
        category: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseCategory"),
            trigger: "change"
          }
        ],
        lengthSchooling: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseLengthSchooling"),
            trigger: "change"
          }
        ],
        isArts: [
            {
                required: true,
                message: this.$t("culture.rules.plsChooseIsArts"),
                trigger: "change"
            }
        ],
        startTime: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseBeginSemester"),
            trigger: "change"
          }
        ],
        endTime: [
          {
            required: true,
            message: this.$t("culture.rules.plsChooseEndSemester"),
            trigger: "change"
          }
        ]
      }
    };
  },
  created() {
    this.$store.getters.getFuncUnderPage(this.$route.path).then(funcs => {
      this.functions = funcs;
    });
  },
  mounted() {
    this.initOptions();
    this.initProjId();
    this.initTrainingLevelOptions();
    this.getCampusProfessions();
    this.getCategoryList();
    this.initSemester();

  },
  computed: {
    watchTraLevel() {
      const obj = {
        trainingLevel: this.model.trainingLevel,
        grade: this.model.grade
      };
      return obj;
    },
    //监听类别
    watchcategory() {
      const obj = {
        category: this.model.category
      };
      return obj;
    },
    //监听学科门类
    watchCategoryCode() {
      const obj = {
        categoryCode: this.model.categoryCode
      };
      return obj;
    },
    //监听专业类
    watchProClassCode() {
      const obj = {
        categoryCode: this.model.professionClassCode
      };
      return obj;
    }
  },
  watch: {
    watchTraLevel: {
      handler: function(newVal, oldVal) {
        if(!this.isClearBelong){
            this.isClearBelong=true;
        }else{
            this.model.belongBigProfession=null;
        }
        this.getBelongBigPro();
        //预科时，清除学科门类/专业类/教育部专业
        if (this.model.trainingLevel == 5) {
          this.isYuKe = true;
          this.model.categoryCode = null;
          this.model.professionClassCode = null;
          this.model.ministryEduCode = null;
          this.options.professionClass=[];
          this.options.ministryEduCode=[];
        } else {
          this.isYuKe = false;
        }
      },
      deep: true
    },
    watchcategory: {
      handler: function(newVal, oldVal) {
        if(!this.isClearCate){
            this.isClearCate=true;
        }else{
            this.model.belongBigProfession=null;
        }
        this.getBelongBigPro();             
      },
      deep: true
    },
    //监听学科门类
    watchCategoryCode: {
      handler: function(newVal, oldVal) {
        if (this.model.trainingLevel != 5) {
          if (!this.isClearCateCode) {            
            this.isClearCateCode = true;
          } else {
            this.model.professionClassCode = null;
            this.model.ministryEduCode = null;
          }
          if(this.model.categoryCode){
              this.getProfessionClassList();
          }else{
              this.options.professionClass=[];
          }          
        }
      },
      deep: true
    },
    watchProClassCode: {
      handler: function(newVal, oldVal) {
        if (this.model.trainingLevel != 5) {
          if (!this.isClearProCode) {
            this.isClearProCode = true;
          } else {
            this.model.ministryEduCode = null;            
          }
          if(this.model.professionClassCode){
              this.getEduProCode();
          }else{
              this.options.ministryEduCode=[];
          }
        }
        deep: true;
      }
    },
    pathKey(val, oldVal) {
      if (val == "main") {
        this.getCampusProfessions();
      }
    }
  },
  methods: {
    initProjId() {
      let currentUser =
        (this.$store.state.session && this.$store.state.session.user) ||
        JSON.parse(localStorage.getItem("user"));
      this.queryForm.projId = currentUser.currentManageDptId;
    },
    initTrainingLevelOptions() {
      findTrainingLevelByProjId(this.queryForm.projId).then(res => {
        if (res.code === 200) {
          this.queryForm.trainingLevel = "";
          this.options.trainingLevel = res.data;
          this.loadTrainingLevelOptions("trainingLevel", res.data);
        }
      });
    },
    initSemester() {
      if (this.options.beginSemester.length > 0) return;
      let years = [];
      for (let i = 1; i < 11; i++) {
        years.push({
          label: this.getSemester(i),
          value: Number(i)
        });
      }
      this.options.beginSemester = years;
      this.options.endSemester = years;
    },
    getSemester(n) {
      if (n) return `第${this.$utils.numberToChinese(n)}学期`;
      else return this.$t("professions.plsChooseTrem");
      /*
              	let lang = this.$store.getters.language || "cn";
			if (lang == "cn") {
				 if (n) return  `第${this.$utils.numberToChinese(n)}学期`;
                 else return this.$t('professions.plsChooseTrem');
			} else {
				 if (n) return  `the ${this.$utils.numberToChinese(n)} term`;
                else return this.$t('professions.plsChooseTrem');
			}
            */
    },
    handleSemesterChange1(type) {
      if (
        this.model.endTime &&
        this.model.startTime &&
        this.model.startTime > this.model.endTime
      ) {
        this.$message({
          type: "warning",
          message: this.$t("professions.termLimited")
        });
        if (type == 1) this.model.startTime = "";
        else this.model.endTime = "";
      }
    },
    isCateReq(rule, code, callback) {
      if (!this.isYuKe) {
        if (code.length == 0) {
          callback(new Error(this.$t("culture.rules.plsChoose")));
        } else {
          callback();
        }
      } else {
        callback();
      }
    },
    getCampusProfessions() {
      let postData = _.cloneDeep(this.queryForm);
      postData.grade = Number(postData.grade);
      findCampusProfessionList(postData).then(res => {
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.queryForm.pageNum_ = res.data.pageNum_;
          this.queryForm.pageSize_ = res.data.pageSize_;
          this.queryForm.total_ = res.data.total_;
        }
      });
    },
    onPageSizeChange(size) {
      this.queryForm.pageSize_ = size;
      this.getCampusProfessions();
    },
    onCurrentPageChange(currentPage) {
      this.queryForm.pageNum_ = currentPage;
      this.getCampusProfessions();
    },

    directionDetail(data) {
      this.pathKey = "dirName";
      this.path.children[0].children[0].children[0].label = data.professionName;
      this.$refs["administrativeClassBread"].getOptions(data);
    },
    getCategoryList() {
      findCategoryList().then(res => {
        if (res.code == 200) {
          this.options.categoryCode = [];
          for (const item of res.data) {
            this.options.categoryCode.push({
              value: item.code,
              label: item.name + "(" + item.code + ")"
            });
          }
        }
      });
    },
    getProfessionClassList() {
      let categoryCodeArr = this.model.categoryCode;
      let data = "?category=";
      this.options.professionClass = [];
        findProfessionClassList(data + categoryCodeArr).then(res => {
          if (res.code == 200) {
            for (const item of res.data) {
              this.options.professionClass.push({
                value: item.code,
                label: item.name + "(" + item.code + ")"
              });
            }
          }
        });
    },
    getEduProCode() {
        let data = "?category=";
        this.options.ministryEduCode = [];
        findProfessionList(data + this.model.categoryCode + "&proClass=" + this.model.professionClassCode)
        .then(res => {
            if (res.code == 200) {
                for (const item of res.data) {
                this.options.ministryEduCode.push({
                    value: item.code,
                    label: item.name + "(" + item.code + ")"
                });
                }
            }
        });
    },
    getBelongBigPro() {
        this.options.belongBigProfession = [];
        if (this.model.category == 2 && this.model.grade && this.model.trainingLevel) {
            let param = {};
            param.grade = this.model.grade;
            param.trainingLevel = this.model.trainingLevel;
            param.category = "1";
            findProByParam(param).then(res => {
                if (res.code == 200) {
                let temp = [];
                res.data.length > 0 &&
                    res.data.forEach(e => {
                    temp.push({
                        value: e.professionCateGory,
                        label: `${e.professionCateGoryName}(${e.professionCateGory})`,
                        term:e.lengthSchooling
                    });
                    });
                this.options.belongBigProfession =
                    temp.length > 0 ? Array.from(new Set(temp)) : [];
                }
            });
        }        
    },
    initOptions() {
      const data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ["X_XWLX", "X_XZ"]
      };
      this.options.category.push({
        label: this.$t("culture.profession.profession"),
        value: "2"
      });
      this.options.category.push({
        label: this.$t("culture.profession.bigProfession"),
        value: "1"
      });
      //是否艺术类
      this.options.isArts = [
          {label: this.$t("message.yes"), value: true},
          {label: this.$t("message.no"), value: false}
      ];
      // 查询管理部门为1的培养层次
      findTrainingLevelByProjId(1).then(res => {
        if (res.code === 200) {
          this.loadTrainingLevelOptions("trainingLevel", res.data);
        }
      });
      queryDic(data)
        .then(res => {
          if (res.code == 200) {
            UTILS.fillSelect(
              {
                // trainingLevel: "X_PYCC",
                // faculty: "X_YX",
                allToDegree: "X_XWLX",
                lengthSchooling: "X_XZ"
              },
              res.data,
              this.options
            );
          }
        })
        .catch(error => {
          console.log(error);
        });
      getFacultys().then(res => {
        if (res.code == 200) {
          for (const item of res.data) {
            this.options.faculty.push({
            label: item.deptName,
            value: item.deptCode
            });
          }
        }
      });
    },
    loadTrainingLevelOptions(optionKey, dataObj) {
      this.options[optionKey] = [];
      _.each(dataObj, level => {
        this.options[optionKey].push({
          label:
            "en" === this.$store.getters.language ? level.nameEN : level.nameCN,
          value: level.code
        });
      });
    },
    //查看
    viewProfession(row) {
      this.showDialog = true;
      this.bindProfession(row);
    },
    getCampusEduProRelations() {
      if(!this.model.categoryCode){
        return;
      }
      let campusEduProRelations = {};
      campusEduProRelations.categoryCode = this.model.categoryCode;
      campusEduProRelations.professionClassCode = this.model.professionClassCode;
      campusEduProRelations.ministryEduCode = this.model.ministryEduCode;
      this.model.campusEduProRelations.push(campusEduProRelations);
    },
    reset() {
      this.queryForm.grade = "";
      this.queryForm.trainingLevel = "";
      this.queryForm.faculty = "";
      this.queryForm.keyWord = "";
      this.queryForm.copyGrade = "";
      this.queryForm.category = "";
      this.queryForm.isArts = null;
      this.getCampusProfessions();
    },
    // 清除表单校验
    resetFormValidate() {
      this.$refs.model.resetFields();
    },
    findToDegreeListByTrainingLevelId(val) {
      this.model.toDegree = [];
      findDegreeTypeByTrainingLevel({
        trainingLevel: val,
        type: "G_XWDM"
      }).then(res => {
            if (res.code == 200&&res.data) {
                this.options.toDegree = res.data.map(item => ({
                label:
                  "en" === this.$store.getters.language
                    ? item.nameEN
                    : item.nameCN,
                value: item.code
              }));
            }
        })
    },
    bindDirection(param){
        findDirMaintenByPro(param).then(res => {
        if (res.code == 200&& res.data) {
           this.direcModel.direction=res.data.map(direction=>direction.name).join(',')
        }
      });
    },
    bindProfession(data){
        let param = {};
        param.grade = data.grade;
        param.professionCode = data.professionCode;
        this.bindDirection(param);
        this.findToDegreeListByTrainingLevelId(data.trainingLevel);
        findCampusProById(data.id).then(res => {
            if (res.code == 200) {
                this.isClearCateCode = false;
                this.isClearProCode = false;
                this.isClearBelong = false;
                this.isClearCate = false;
                res.data.grade = res.data.grade + "";         
                res.data.categoryCode = null;
                res.data.professionClassCode = null;
                res.data.ministryEduCode = null;
                res.data.isArts=res.data.isArts||false;
                this.model = res.data;
                if (res.data.toDegree && res.data.toDegree.length) {
                    this.model.toDegree = res.data.toDegree.split(",");
                } else {
                    this.model.toDegree = [];
                }
                //匹配年级
                let relations=res.data.campusEduProRelations.filter(pro=>pro.grade==data.grade);
                if(relations.length>0){
                    this.model.categoryCode = relations[0].categoryCode;
                    this.model.professionClassCode =  relations[0].professionClassCode;
                    this.model.ministryEduCode =  relations[0].ministryEduCode;
                }
            }
        });
    }
  }
};
</script>
<style lang="scss">
#schoolMajorDiv {
  .el-dialog__body {
    padding: 30px 20px;
    color: #606266;
    font-size: 14px;
    min-height: 330px;
  }
}
</style>

